package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * Created with IntelliJ IDEA
 *
 * @Auther: 宋港迎
 * @Date: 2020/08/21/14:18
 * @Destription:
 */
@Getter
public enum RuleSettingEnum {

    /**
     * 关联业务中的规则
     */
    NEW_FOLLOW_UP_RECORD_VISITING_TIME("newFollowUpRecordVisitingTime","new_follow_up_record_visiting_time", "enum.ruleSetting.name.new_follow_up_record_visiting_time", "1", XbbSetUpdateRuleEnum.ASSOCIATED_BUSINESS.getCode()),
    NEW_CONTRACT_ORDER_CREATE_TIME("newContractOrderCreateTime","new_contract_order_create_time", "enum.ruleSetting.name.new_contract_order_create_time", "1", XbbSetUpdateRuleEnum.ASSOCIATED_BUSINESS.getCode()),
    NEW_OPPORTUNITIES_CREATE_TIME("newOpportunitiesCreateTime","new_opportunities_create_time", "enum.ruleSetting.name.new_opportunities_create_time", "1", XbbSetUpdateRuleEnum.ASSOCIATED_BUSINESS.getCode()),
    NEW_SIGN_IN_CHECK_IN_TIME("newSignInCheckInTime","new_sign_in_check_in_time", "enum.ruleSetting.name.new_sign_in_check_in_time", "1", XbbSetUpdateRuleEnum.ASSOCIATED_BUSINESS.getCode()),


    /**
     * 通话记录中的规则
     */
    TELEPHONE_CONNECTION_DIAL_TIME("telephoneConnectionDialTime","telephone_connection_dial_time", "enum.ruleSetting.name.telephone_connection_dial_time", "1", XbbSetUpdateRuleEnum.CALL_LOG.getCode()),

    /**
     * 客户阶段中的规则
     */
    STAGE_JUMP_GO_TO_TIME("stageJumpGoToTime","stage_jump_go_to_time", "enum.ruleSetting.name.stage_jump_go_to_time", "1", XbbSetUpdateRuleEnum.CUSTOMER_STAGE_LIST.getCode()),
    COMPLETE_PHASE_WORK_COMPLETION_TIME("completePhaseWorkCompletionTime","complete_phase_work_completion_time", "enum.ruleSetting.name.complete_phase_work_completion_time", "1", XbbSetUpdateRuleEnum.CUSTOMER_STAGE_LIST.getCode()),
    FILLING_IN_STAGE_FEEDBACK_CREATE_TIME("fillingInStageFeedbackCreateTime","filling_in_stage_feedback_create_time", "enum.ruleSetting.name.filling_in_stage_feedback_create_time", "1", XbbSetUpdateRuleEnum.CUSTOMER_STAGE_LIST.getCode());

    /**
     * 配置别名
     */
    private final String config;
    /**
     * 数据库字段
     */
    private final String dbAlias;
    /**
     * 配置名称
     */
    private final String name;
    /**
     * 配置值
     */
    private final String configValue;
    /**
     * 业务类型
     */
    private Integer businessType;

    RuleSettingEnum(String config, String dbAlias, String name, String configValue, Integer businessType) {
        this.config = config;
        this.name = name;
        this.dbAlias = dbAlias;
        this.configValue = configValue;
        this.businessType = businessType;
    }

    public static RuleSettingEnum getByConfig(String config) {
        RuleSettingEnum configEnum = null;
        for (RuleSettingEnum ruleSettingEnum : RuleSettingEnum.values()) {
            if (Objects.equals(config, ruleSettingEnum.getConfig())) {
                configEnum = ruleSettingEnum;
            }
        }
        return configEnum;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }

    public static List<String> getConfigs() {
        List<String> configs = new ArrayList<>();
        for (RuleSettingEnum ruleSettingEnum : RuleSettingEnum.values()) {
            configs.add(ruleSettingEnum.getConfig());
        }
        return configs;
    }

}
